package com.bizmerce.rnd.oms.decision.criterion;

import java.util.List;

import com.bizmerce.rnd.oms.decision.data.BillOfMaterials;
import com.bizmerce.rnd.oms.decision.data.RawMaterial;

/**
 * 대상협정: 한-아세안 FTA, 한-미 FTA, 한-인도 CEPA
 * 공제법: Build-down Method;
 * value FOB 또는 AV(Adjusted Value)
 * vnm Value of Non-originating Material
 */
public class BuildDownMethod extends LocalContents {

	//return Math.floor((value - vnm) / value * 100);
	
	//중간재 규정을 적용한다.
	//가치를 가져올때 FTA에 해당되는 가격을 가져와야 한다.
	public Boolean assign(BillOfMaterials bom) {
		double fobValue = bom.getSalePrice();
		double vnmValue = 0.;
		List<RawMaterial> materials = bom.getRawMaterials();
		for (RawMaterial rawMaterial : materials) {
			if(rawMaterial.isNotIntraItem()) {
				vnmValue +=  rawMaterial.getPurchasePrice();
			}
		}	
		
		boolean result = false;
		double value = Math.floor((fobValue - vnmValue) / fobValue * 100);
		System.out.println("BD:" + value + "%");
		result = (value >= 45); //45%
		return result;
	}
}
